﻿' Culling Modes
Const CULL_NONE:Int				= 1
Const CULL_CLOCKWISE:Int		= 2
Const CULL_ANTICLOCKWISE:Int	= 3

' Manual Culling Modes
Const MANUAL_CULL_NONE:Int		= 1
Const MANUAL_CULL_BACK:Int		= 2
Const MANUAL_CULL_FRONT:Int		= 3

' Shade Options
Const SO_FLAT:Int				= 0
Const SO_GOURAUD:Int			= 1
Const SO_PHONG:Int				= 2

' Scene Blend Types
Const SBT_TRANSPARENT_ALPHA:Int = 0
Const SBT_TRANSPARENT_COLOUR:Int= 1
Const SBT_ADD:Int				= 2
Const SBT_MODULATE:Int			= 3
Const SBT_REPLACE:Int			= 4


Type Material Extends BaseObject
	Field _materialName:String
	Field _color:ColourValue
	Global _tech:TList
	Global _materials:TList
	
	Method New()
		Self._typ = ET_MATERIAL	
		If Self._tech = Null Then Self._tech = New TList
		if self._materials = null then self._materials = new TList
	End Method
	
	Function getFromHandle:Material(hnd:Int)
		Return Material(HandleToObject(hnd))
	End Function
	
rem
bbdoc: Returns the name of this object. 
endrem
	Method getName:String()
		Return o_material_getName(Self._ptr)
	End Method
	
rem
bbdoc: Creates a new copy of this material with the same settings but a new name. 
about: <p><b>Parameters:</b></p>
<table cellpadding="4" cellspacing="4" border="0">
<tr><td><i>newName</i></td><td>The name for the cloned material</td></tr>
<tr><td><i>changeGroup</i></td><td>If true, the resource group of the clone is changed</td></tr>
<tr><td><i>newGroup</i></td><td>Only required if changeGroup is true; the new group to assign</td></tr>
</table>
endrem
	Method clone:Material(newName:String, changeGroup:Byte = False, newGroup:String = "")
		Local nG:Byte ptr = Null
		If newGroup.Length Then nG = newGroup.ToCString()
		Local mat:Material = New Material
		
		mat._ptr			= o_material_clone(Self._ptr, newName.ToCString(), changeGroup, nG)
		mat._typ			= ET_NO_ENTITY
		mat._materialName	= newName
		
		Return mat
	End Method
	
rem
bbdoc: Sets the diffuse colour reflectance properties of every Pass in every Technique. 
about: <p>This property has been moved to the Pass class, which is accessible via the Technique. 
For simplicity, this method allows you to set these properties for every current Technique, and for every 
current Pass within those Techniques. If you need more precision, retrieve the Technique and Pass instances 
and set the property there.<p>
<p><b>See also:</b> Pass::setDiffuse</p>
endrem
	Method setDiffuse(r:Float, g:Float, b:Float, a:Float = 1.0)
		o_material_setDiffuse(Self._ptr, r, g, b, a)
	End Method
	
rem
bbdoc: Sets the shininess properties of every Pass in every Technique. 
about: This property has been moved to the Pass class, which is accessible via the Technique. For simplicity, 
this method allows you to set these properties for every current Technique, and for every current Pass within 
those Techniques. If you need more precision, retrieve the Technique and Pass instances and set the property 
there.
<p><b>See also:</b> Pass::setShininess</p>
endrem
	Method setShininess(shininess:Float)
		o_material_setShininess(Self._ptr, shininess)
	End Method
	
rem
bbdoc: Sets the ambient colour reflectance properties for every Pass in every Technique. 
about: <p>This property has been moved to the Pass class, which is accessible via the Technique. For simplicity, 
this method allows you to set these properties for every current Technique, and for every current Pass within 
those Techniques. If you need more precision, retrieve the Technique and Pass instances and set the property 
there.</p>
<p><b>See also:</b> Pass::setAmbient</p>
endrem
	Method setAmbient(r:Float, g:Float, b:Float)
		o_material_setAmbient(Self._ptr, r, g, b)
	End Method
	
rem
bbdoc: Sets the specular colour reflectance properties of every Pass in every Technique. 
about: <p>This property has been moved to the Pass class, which is accessible via the Technique. For simplicity, 
this method allows you to set these properties for every current Technique, and for every current Pass within 
those Techniques. If you need more precision, retrieve the Technique and Pass instances and set the property 
there.</p>
<p><b>See also:</b> Pass::setSpecular</p>
endrem
	Method setSpecular(r:Float, g:Float, b:Float, a:Float = 1.0)
		o_material_setSpecular(Self._ptr, r, g, b, a)
	End Method
	
rem
bbdoc: Sets the amount of self-illumination of every Pass in every Technique. 
about: <p>This property has been moved to the Pass class, which is accessible via the Technique. For simplicity, 
this method allows you to set these properties for every current Technique, and for every current Pass within 
those Techniques. If you need more precision, retrieve the Technique and Pass instances and set the property 
there.</p>
<p><b>See also:</b> Pass::setSelfIllumination</p>
endrem
	Method setSelfIllumination(r:Float, g:Float, b:Float)
		o_material_setSelfIllumination(Self._ptr, r, g, b)
	End Method
	
rem
bbdoc: Sets whether objects using this material will receive shadows.
about: <p>This method allows a material to opt out of receiving shadows, if it would otherwise do so. Shadows 
will not be cast on any objects unless the scene is set up to support shadows (See also: SceneManager::setShadowTechnique), 
and not all techniques cast shadows on all objects. In any case, if you have a need to prevent shadows being 
received by material, this is the method you call to do it.</p>
<p><b>Note: Transparent materials never receive shadows despite this setting. The default is to receive shadows.</b></p>
endrem
	Method setReceiveShadows(enabled:Byte)
		o_material_setReceiveShadows(Self._ptr, enabled)
	End Method
	
rem
bbdoc: Sets the point size properties for every Pass in every Technique. 
about: <p>This property has been moved to the Pass class, which is accessible via the Technique. For simplicity, 
this method allows you to set these properties for every current Technique, and for every current Pass within 
those Techniques. If you need more precision, retrieve the Technique and Pass instances and set the property 
there.</p>
<p><b>See also:</b> Pass::setPointSize</p>
endrem
	Method setPointSize(ps:Float)
		o_material_setPointSize(Self._ptr, ps)
	End Method
	
rem
bbdoc: 'Compiles' this Material. 
about: <p>Compiling a material involves determining which Techniques are supported on the card on which OGRE 
is currently running, and for fixed-function Passes within those Techniques, splitting the passes down where 
they contain more TextureUnitState instances than the current card has texture units.</p>
<p>This process is automatically done when the Material is loaded, but may be repeated if you make some 
procedural changes.</p>
<p><b>Parameters:</b></p>
<table cellpadding="4" cellspacing="4" border="0">
<tr>
	<td><i>autoManageTextureUnits</i></td>
	<td>
		If true, when a fixed function pass has too many TextureUnitState entries than the card has texture 
		units, the Pass in question will be split into more than one Pass in order to emulate the Pass. If 
		you set this to false and this situation arises, an Exception will be thrown. 
	</td>
</tr>
</table>
endrem
	Method Compile(autoManageTextureUnits:Byte = True)
		o_material_compile(Self._ptr, autoManageTextureUnits)
	End Method
	
rem
bbdoc: Sets whether or not each Pass renders with depth-buffer checking on or not.
about: <p>This property has been moved to the Pass class, which is accessible via the Technique. For 
simplicity, this method allows you to set these properties for every current Technique, and for every 
current Pass within those Techniques. If you need more precision, retrieve the Technique and Pass instances 
and set the property there.</p>
<p><b>See also:</b> Pass::setDepthCheckEnabled</p>
endrem
	Method setDepthCheckEnabled(enabled:Byte)
		o_material_setDepthCheckEnabled(Self._ptr, enabled)
	End Method
	
rem
bbdoc: Sets whether or not each Pass renders with depth-buffer writing on or not. 
about: <p>This property has been moved to the Pass class, which is accessible via the Technique. For 
simplicity, this method allows you to set these properties for every current Technique, and for every 
current Pass within those Techniques. If you need more precision, retrieve the Technique and Pass instances 
and set the property there.</p>
<p><b>See also:</b> Pass::setDepthWriteEnabled</p>
endrem
	Method setDepthWriteEnabled(enabled:Byte)
		o_material_setDepthWriteEnabled(Self._ptr, enabled)
	End Method
	
rem
bbdoc: 
about: <p>This property has been moved to the Pass class, which is accessible via the Technique. For 
simplicity, this method allows you to set these properties for every current Technique, and for every 
current Pass within those Techniques. If you need more precision, retrieve the Technique and Pass instances 
and set the property there.</p>
<p><b>See also:</b> Pass::setColourWriteEnabled</p>
endrem
	Method setColourWriteEnabled(enabled:Byte)
		o_material_setColourWriteEnabled(Self._ptr, enabled)
	End Method
	
rem
bbdoc: Sets the culling mode for each pass based on the 'vertex winding'. 
about: <p>This property has been moved to the Pass class, which is accessible via the Technique. For 
simplicity, this method allows you to set these properties for every current Technique, and for every 
current Pass within those Techniques. If you need more precision, retrieve the Technique and Pass instances 
and set the property there.</p>
<p><b>See Also:</b> Pass::setCullingMode</p>
endrem
	Method setCullingMode(mode:Int)
		o_material_setCullingMode(Self._ptr, mode)
	End Method
	
rem
bbdoc: Sets the manual culling mode, performed by CPU rather than hardware. 
about: <p>This property has been moved to the Pass class, which is accessible via the Technique. For 
simplicity, this method allows you to set these properties for every current Technique, and for every 
current Pass within those Techniques. If you need more precision, retrieve the Technique and Pass instances 
and set the property there.</p>
<p><b>See Also:</b> Pass::setManualCullingMode</p>
endrem
	Method setManualCullingMode(mode:Int)
		o_material_setManualCullingMode(Self._ptr, mode)
	End Method
	
rem
bbdoc: Sets whether or not dynamic lighting is enabled for every Pass. 
about: <p>This property has been moved to the Pass class, which is accessible via the Technique. For 
simplicity, this method allows you to set these properties for every current Technique, and for every 
current Pass within those Techniques. If you need more precision, retrieve the Technique and Pass instances 
and set the property there.</p>
<p><b>See Also:</b> Pass::setLightingEnabled</p>
endrem
	Method setLightingEnabled(enabled:Byte)
		o_material_setLightingEnabled(Self._ptr, enabled)
	End Method
	
rem
bbdoc: Sets the type of light shading required. 
about: <p>This property has been moved to the Pass class, which is accessible via the Technique. For 
simplicity, this method allows you to set these properties for every current Technique, and for every 
current Pass within those Techniques. If you need more precision, retrieve the Technique and Pass instances 
and set the property there.</p>
<p><b>See Also:</b> Pass::setShadingMode</p>
endrem
	Method setShadingMode(mode:Int)
		o_material_setShadingMode(Self._ptr, mode)
	End Method
	
rem
bbdoc: Sets the fogging mode applied to each pass. 
about: <p>This property has been moved to the Pass class, which is accessible via the Technique. For 
simplicity, this method allows you to set these properties for every current Technique, and for every 
current Pass within those Techniques. If you need more precision, retrieve the Technique and Pass instances 
and set the property there.</p>
<p><b>See Also:</b> Pass::setFog</p>
endrem
	Method setFog(overrideScene:Byte, mode:Int = FOG_NONE, colour:ColourValue = Null, expDensity:Float = 0.001, linearStart:Float = 0.0, linearEnd:Float = 1.0)
		If colour = Null Then colour = ColourValue.WHITE()
		o_material_setFog(Self._ptr, overrideScene, mode, colour.toC(), expDensity, linearStart, linearEnd)
	End Method
	
rem
bbdoc: Sets the depth bias to be used for each Pass.
about: <p>This property has been moved to the Pass class, which is accessible via the Technique. For 
simplicity, this method allows you to set these properties for every current Technique, and for every 
current Pass within those Techniques. If you need more precision, retrieve the Technique and Pass instances 
and set the property there.</p>
<p><b>See Also:</b> Pass::setDepthBias</p>
endrem
	Method setDepthBias(constantBias:Float, slopeScaleBias:Float)
		o_material_setDepthBias(Self._ptr, constantBias, slopeScaleBias)
	End Method
	
rem
bbodc: Set texture filtering for every texture unit in every Technique and Pass. 
about: <p>This property has been moved to the Pass class, which is accessible via the Technique. For 
simplicity, this method allows you to set these properties for every current Technique, and for every 
current Pass within those Techniques. If you need more precision, retrieve the Technique and Pass instances 
and set the property there.</p>
<p><b>See Also:</b> Pass::setTextureFiltering</p>
endrem
	Method setTextureFiltering(filterType:Int)
		o_material_setTextureFiltering(Self._ptr, filterType)
	End Method
	
rem
bbdoc: Sets the anisotropy level to be used for all textures. 
about: <p>This property has been moved to the Pass class, which is accessible via the Technique. For 
simplicity, this method allows you to set these properties for every current Technique, and for every 
current Pass within those Techniques. If you need more precision, retrieve the Technique and Pass instances 
and set the property there.</p>
<p><b>See Also:</b> Pass::setTextureAnisotropy</p>
endrem
	Method setTextureAnisotropy(maxAniso:Int)
		o_material_setTextureAnisotropy(Self._ptr, maxAniso)
	End Method
	
rem
bbdoc: Sets the kind of blending every pass has with the existing contents of the scene. 
about: <p>This property has been moved to the Pass class, which is accessible via the Technique. For 
simplicity, this method allows you to set these properties for every current Technique, and for every 
current Pass within those Techniques. If you need more precision, retrieve the Technique and Pass instances 
and set the property there.</p>
<p><b>See Also:</b> Pass::setSceneBlending</p>
endrem
	Method setSceneBlending(sbt:Int)
		o_material_setSceneBlending(Self._ptr, sbt)
	End Method
	
rem
bbdoc: Gets the indexed technique. 
endrem
	Method getTechnique:Technique(index:Int)
		Local tech:Technique
		Local found:Byte = False
		Local p:Byte ptr = o_material_getTechnique(Self._ptr, index)
		If Self._tech <> Null
			For Local i:Technique = EachIn Self._tech
				If i._ptr = p
					found	= True
					tech	= i
					Exit
				EndIf
			Next
		EndIf
		
		If found = False
			tech		= New Technique
			tech._ptr	= p
			tech._typ	= ET_TECHNIQUE
			Self._tech.AddLast(tech)
		End If
		
		Return tech
	End Method
	
rem
bbdoc: searches for the named technique. 
about: Return 0 if technique with name is not found 
endrem
	Method getTechniqueByName:Technique(techName:String)
		Local tech:Technique = New Technique
		tech._ptr = o_material_getTechniqueByName(Self._ptr, techName.ToCString())
		tech._typ = ET_NO_ENTITY
		
		return tech
	End Method
	
rem
bbdoc: Determines if the material has any transparency with the rest of the scene (derived from whether any 
Techniques say they involve transparency). 
endrem
	Method isTransparent:Byte()
		Return o_material_isTransparent(Self._ptr)
	End Method
	
rem
bbdoc: Returns whether or not objects using this material will receive shadows. 
endrem
	Method getReceiveShadows:Byte()
		Return o_material_getReceiveShadows(Self._ptr)
	End Method
	
rem
bbdoc: Sets whether objects using this material be classified as opaque to the shadow caster system. 
about: <p>This method allows a material to cast a shadow, even if it is transparent. By default, transparent 
materials neither cast nor receive shadows. Shadows will not be cast on any objects unless the scene is set 
up to support shadows (<b>See also:</b> SceneManager::setShadowTechnique), and not all techniques cast 
shadows on all objects.</p>
endrem
	Method setTransparencyCastsShadows(enabled:Byte)
		o_material_setTransparencyCastsShadows(Self._ptr, enabled)
	End Method
	
rem
bbdoc: Returns whether or not objects using this material be classified as opaque to the shadow caster system. 
endrem
	Method getTransparencyCastsShadows:Byte()
		Return o_material_getTransparencyCastsShadows(Self._ptr)
	End Method
	
rem
bbdoc: Creates a new Technique for this Material. 
about: <p>A Technique is a single way of rendering geometry in order to achieve the effect you are intending in 
a material. There are many reason why you would want more than one - the main one being to handle variable 
graphics card abilities; you might have one technique which is impressive but only runs on 4th-generation graphics 
cards, for example. In this case you will want to create at least one fallback Technique. OGRE will work out which 
Techniques a card can support and pick the best one.</p>
<p>If multiple Techniques are available, the order in which they are created is important - the engine will consider 
lower-indexed Techniques to be preferable to higher-indexed Techniques, ie when asked for the 'best' technique it 
will return the first one in the technique list which is supported by the hardware.</p>
endrem
	Method createTechnique:Technique()
		Local tech:Technique = New Technique
		tech._ptr = o_material_createTechnique(Self._ptr)
		tech._typ = ET_TECHNIQUE
		Self._tech.AddLast(tech)
		
		Return tech
	End Method
	
rem
bbdoc: Retrieves the number of techniques. 
endrem
	Method getNumTechniques:Int()
		Return o_material_getNumTechniques(Self._ptr)
	End Method
	
rem
bbdoc: Removes the technique at the given index. 
endrem
	Method removeTechnique(index:Int)
		o_material_removeTechnique(Self._ptr, index)
	End Method
	
rem
bbdoc: Removes all the techniques in this Material. 
endrem
	Method removeAllTechniques()
		o_material_removeAllTechniques(Self._ptr)
	End Method
	
rem
bbdoc: Gets the indexed supported technique. 
endrem
	Method getSupportedTechnique:Technique(index:Int)
		Local tech:Technique
		Local found:Byte = False
		Local p:Byte ptr = o_material_getSupportedTechnique(Self._ptr, index)
		For Local i:Technique = EachIn Self._tech
			If i._ptr = p
				found	= True
				tech	= i
				Exit
			EndIf
		Next
		
		If found = False
			tech		= New Technique
			tech._ptr	= p
			tech._typ	= ET_TECHNIQUE
			Self._tech.AddLast(tech)
		End If
		
		Return tech
	End Method
	
rem
bbdoc: Retrieves the number of supported techniques. 
endrem
	Method getNumSupportedTechniques:Int()
		Return o_material_getNumSupportedTechniques(Self._ptr)
	End Method
	
rem
bbdoc: Gets a string explaining why any techniques are not supported. 
endrem
	Method getUnsupportedTechniquesExplanation:String()
		Return o_material_getUnsupportedTechniquesExplanation(Self._ptr)
	End Method
	
rem
bbdoc: Gets the number of levels-of-detail this material has in the given scheme, based on Technique::setLodIndex.
about: <b>Note:</b> Note that this will not be up to date until the material has been compiled. 
endrem
	Method getNumLodLevels:Int(schemeIndex:Int)
		Return o_material_getNumLodLevels(Self._ptr, schemeIndex)
	End Method
	
rem
bbdoc: Gets the best supported technique. 
about: <p>This method returns the lowest-index supported Technique in this material (since lower-indexed Techniques 
are considered to be better than higher-indexed ones).</p>
<p>The best supported technique is only available after this material has been compiled, which typically happens on 
loading the material. Therefore, if this method returns NULL, try calling Material::load.</p>
<p><b>Parameters:</b></p>
<table cellpadding="4" cellspacing="4" border="0">
<tr><td><i>lodIndex</i></td><td>The material lod index to use</td></tr>
<tr><td><i>rend</i></td><td>
Optional parameter specifying the Renderable that is requesting this technique. Only used if no valid technique for 
the active material scheme is found, at which point it is passed to MaterialManager::Listener::handleSchemeNotFound 
as information.</td></tr>
</table>
endrem
	Method getBestTechnique:Technique(lodIndex:Int = 0, rend:BaseObject = Null)
		Local r:Byte ptr = Null
		If rend <> Null Then r = rend._ptr
		o_material_getBestTechnique(Self._ptr, lodIndex, r)
	End Method
	
End Type